function HandleTableProduces(gui, item, options) {
  this._gui = gui;
  this._item = item;
  this._options = options;
  this._popupBox = new PopupBox();
  this._popupBox2 = new PopupBox2();
  
  this._events = (options && options.events) ? options.events : [];
  this._user = (options && options.user) ? options.user : null;
  this._date = (options && options.date) ? options.date : null;
  this._noExist = (options && options.noExist) ? options.noExist : false;
  this._isSupervise = (options && options.s) ? options.s : 0;
  this._createElements();
}

HandleTableProduces.prototype._createElements = function() {
  var tr, td, _self = this;
  /*---Last Updated-----*/
  if (!this._noExist && !this._options.mails && !this._isSupervise) {
    if (this._events.length == 0) {
      tr = this._gui.table1.insertRow(-1);
      td = tr.insertCell(-1);
      td.colSpan = 7;
      td.style.height = '25px';
      td.style.backgroundColor = '#ffffff';
      td.style.textAlign = 'center';
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderLeft = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.appendChild(document.createTextNode('N/A'));
    }
    for (var j = 0, jl = this._events.length; j < jl; j++) {
      var event = this._events[j];
      if (j < 3) {
        tr = this._gui.table1.insertRow(-1);
        tr.style.backgroundColor = (j % 2 == 0) ? '#fff' : '#ccc';
        new TableRowLastUpdatedProduce(tr, event, {user: this._user, date: this._date, isPage: true, hidePrice: true, callback: _self._options.callback} );
      }
    }
    if (this._events.length > 3) {
      var a = document.createElement('a');
      a.appendChild(document.createTextNode('Find all'));
      a.href = '#';
      if (this._user.type == Constant.USER_TYPE_MANAGER_ASSISTANT) {
        a.onclick = function() {  var w = window.open('?p=pageasst&t=pagelastupdatedproduce&m={"a":1,"b":1,"c":1}', 'Last Updated', 'width=1024,height=768,scrollbars=1,location=0', true);
                                  w.focus();
                                  return false;
                               };
      } else {
        a.onclick = function() { var w = window.open('?p=pageserv&t=pagelastupdatedproduce&m={"a":1,"b":1,"c":1}', 'Last Updated', 'width=1024,height=768,scrollbars=1,location=0', true);
                                 w.focus();
                                 return false;
                               };
      }
      this._gui.moreDiv.appendChild(a);
    }
    /*---ADD CUSTOMIZE TASK---*/
    this._gui.addTask.onclick = function() { var produce = Produce.instance();
                                             var div = document.createElement('div');
                                             var func1 = function() { if (produce.customTask != '') {
                                                                        _self._popupBox2._close();
                                                                        new RequestUtils()._write('produce', [produce], [], function() { if (_self._user.type == Constant.USER_TYPE_MANAGER_ASSISTANT) {
                                                                                                                                           location.href = '?p=pageasst&t=pageb1asstcustomworks&m={"a":1,"b":1,"c":1,"d":17}'; 
                                                                                                                                         } else if (_self._user.type == Constant.USER_TYPE_CUSTOMER_SERVICE){
                                                                                                                                           location.href = '?p=pageserv&t=pageb1servcustomworks&m={"a":1,"b":1,"c":1, "d":20}';
                                                                                                                                         } else if (_self._user.type == Constant.USER_TYPE_MANAGER){
                                                                                                                                           location.href = '?p=pageserv&t=pageb1managercustomworks&m={"a":1,"b":1,"c":1, "d":1}';
                                                                                                                                         } else if (_self._user.type == Constant.USER_TYPE_ACCOUNTANT){
                                                                                                                                           location.href = '?p=pageserv&t=pageb1acctcustomworks&m={"a":1,"b":1,"c":1, "d":1}';
                                                                                                                                         } 
                                                                                                                                       }, { php: Constant.FACTORY + '/customphp/mysqlwrite.php', pos: DOMUtils.findPos(_self._gui.addTask) });
                                                                      } else {
                                                                        window.alert('Task can not be empty');
                                                                      }
                                                                    };
                                             var func2 = function() { _self._popupBox2._close();
                                                                     };
                                             MiscUtils.dialog(_self._popupBox2, DOMUtils.findPos(this), div, func1, func2, { ok: 'Add', t: 'Add Custom Task', width: 785, height: 200 });
                                             new DialogCustomizeTask(div, produce, {user: _self._user, date: _self._date, produces: _self._item });
                                           };
  }
  
  /*----Produce------*/
  if (this._item.length == 0) {
    tr = this._gui.table.insertRow(-1);
    td = tr.insertCell(-1);
    td.colSpan = 7;
    td.style.height = '40px';
    td.style.backgroundColor = '#fff';
    td.style.textAlign = 'center';
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    td.appendChild(document.createTextNode('N/A'));
  }

  for (var i = 0, il = this._item.length; i < il; i++) {
    var produce = this._item[i];
    
    tr = this._gui.table.insertRow(-1);
    new TableRowProduce(tr, produce, this._options);
  }
};